#ifndef PhysicComponent_H_
#define PhysicComponent_H_


#include "Entities/Component.h"
#include "LibraryFrameworkExport.h"
#include "Game/GameTime.h"
#include "Sprite/SpriteRenderer.h"
#include "Sprite/SpriteTypes.h"
#include "Transform2DComponent.h"
#include "Graphics/Color.h"

#include <iosfwd>
#include <string>

namespace CasaEngine
{
	/*
	 *	
	 */
	class LIBRARY_FRAMEWORK_EXPORT PhysicComponent :
		public Component
	{
	private:
		//radius of the circle collision
		float m_fRadius;

		Vector2F    m_vVelocity;

		//a normalized vector pointing in the direction the entity is heading. 
		Vector2F    m_vHeading;

		//a vector perpendicular to the heading vector
		Vector2F    m_vSide; 

		float       m_fMass;

		//the maximum speed this entity may travel at.
		float       m_fMaxSpeed;

		//the maximum force this entity can produce to power itself 
		//(think rockets and thrust)
		float        m_fMaxForce;

		//the maximum rate (radians per second)this vehicle can rotate         
		float       m_fMaxTurnRate;

		Transform2DComponent* m_pTransform;

	public:
		PhysicComponent(BaseEntity* pEntity_);
		virtual ~PhysicComponent();

		//all entities must implement an Initialize function
		void Initialize();

		//all entities must implement an update function
		void  Update(const GameTime& gameTime_);

		//all entities can communicate using messages. They are sent
		//using the MessageDispatcher singleton class
		//void HandleEvent(const Event* pEvent_);
		
		float GetRadius() const;
		void SetRadius(float val_);

		void Initialize(float radius, Vector2F velocity, float max_speed, 
			Vector2F heading, float mass, float turn_rate, float max_force);

		//accessors
		Vector2F  Velocity()const;
		void      SetVelocity(const Vector2F& NewVel);

		float     Mass()const;

		Vector2F  Side()const;

		float     MaxSpeed()const;                     
		void      SetMaxSpeed(float new_speed);

		float     MaxForce()const;
		void      SetMaxForce(float mf);

		bool      IsSpeedMaxedOut()const;
		float     Speed()const;
		float     SpeedSq()const;

		Vector2F  Heading()const;
		void      SetHeading(Vector2F new_heading);
		bool      RotateHeadingToFacePosition(Vector2F target);

		float     MaxTurnRate()const;
		void      SetMaxTurnRate(float val);

		//entities should be able to read/write their data to a stream
		void Write(std::ostream&  os)const;
		void Read (std::ifstream& is);
	};

}

#endif // PhysicComponent_H_


